const express=require('express');
const router= express.Router();
const act = require('../models/activities');
const { schema } = require('../models/activities');
const { get } = require('mongoose');



router.post('/myactivities',function(req,res){
    res.send(JSON.stringify(req.body)+"收到报文")
    var loginuseract=new act ((req.body))

    loginuseract.save()
})

router.get('/myactivities',function(req,res){
    // console.log(req.query)
    var reqid = req.query.用户.toString()
    var foundAct=[]
    // const query = act.find({"来自用户": reqid  }).sort({ field: 'asc', _id: -1 }).limit(4); 
    // query.setOptions({ lean : true });
    // query.collection(act.collection);
    //     query.exec(function(err,result ){
    //     if(err){
    //         console.log(err);
    //     }
    //     else{
    //         console.log(result.来自用户+result.uploadtime)
    //         foundAct.push(result.answers)
    //     }
    // }
    // )
    // schema.statics.listAll = function listAll(cb) {
    //     act.find({}, cb);
    //   };
    var docs =act.find({"来自用户": reqid}).where({$or: [{'answers.主观题答案': { $ne: [] }},{'answers.选择题答案':{ $ne :[]}}]}).sort({ field: 'asc', _id: -1 });

    docs.select('answers uploadTime 来自用户')
    docs.exec(function(err,data){
            try{
                console.log(data)
                // console.log((data.uploadTime))
                console.log("----------------------")
                }
       catch(err){console.log(err)}
       res.send(JSON.stringify(data))   
    })
    // console.log(Object.keys(docs))
    // console.log(Object.values(docs))

 
    
 
})


module.exports = router